﻿using System;
using System.Web.Configuration;
using System.Data;

public partial class manager_taskexec_view : System.Web.UI.Page
{
    public int taskid = 0;
    DBHelper db = new DBHelper(WebConfigurationManager.ConnectionStrings["connString"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        taskid = Convert.ToInt32(Request.QueryString["taskid"]);
        Edit_Id.Value = taskid.ToString();
        if (!IsPostBack)
        {
            loadEditData(taskid);
        }
    }
    private void loadEditData(int sid)
    {
        string Tzx_psid = Session[AppConfig.SESSION_USER_PSID].ToString();
        string sql = "select * from v_A_Task where id=" + sid;
        DataTable dt = db.getList(sql);
        if (dt.Rows.Count == 1)
        {

            txt_title.Value = dt.Rows[0]["title"].ToString();


            txt_title.Value = dt.Rows[0]["title"].ToString();
            txt_detail.Value = dt.Rows[0]["detail"].ToString();
            Bm_Kh_mc.Value = dt.Rows[0]["Bm_Kh_Mc"].ToString() + "|" + dt.Rows[0]["Ry_Kh_Mc"].ToString();
            Bm_Bkh_mc.Value = dt.Rows[0]["Bm_Bkh_Mc"].ToString() + "|" + dt.Rows[0]["Ry_Bkh_Mc"].ToString();
            ddl_LX_sj.SelectedValue = dt.Rows[0]["LX_sj"].ToString();
            txt_rq_yjs.Value = dt.Rows[0]["rq_yjs"].ToString();
            txt_Tdata.Value = dt.Rows[0]["Tdata"].ToString();

            string isusstr = "0";
            if (dt.Rows[0]["LX_sj"].ToString() == "True")
            {
                isusstr = "1";
                isdata.Value = "1";
            }
            ddl_LX_sj.SelectedValue = isusstr;

            if (dt.Rows[0]["state"].ToString() != "0")
            {
                Button2.Visible = false;
            }
            if (dt.Rows[0]["Ry_Kh"].ToString() != Tzx_psid)
            {
                Button2.Visible = false;
            }

        }
    }


    protected void Button2_Click(object sender, EventArgs e)
    {
        string taskid = Edit_Id.Value;
        string zx_psid = Session[AppConfig.SESSION_USER_PSID].ToString();
        string task_state = ddl_task_state.SelectedValue;
        string Pdata = txt_Pdata.Value;
        string bz_js = txt_bz_js.Value;

        int i = 0;
        if (taskid != "0")
        {
            string sql = "update A_Task set [state]=1,bz_js='" + bz_js + "',rq_sjs=getdate(),Pdata='" + Pdata + "',task_state='" + task_state + "' where id=" + taskid + " and [state]=0";
            i = db.executeNoneQuery(sql);
        }
        if (i > 0)
        {
            Response.Write(CommonHelper.MsgAndRedirectN("任务已完成", "Default.aspx"));
        }
        else
        {
            Response.Write(CommonHelper.MsgAndRedirectN("任务完成失败请核对信息", "Default.aspx"));
        }
    }
}